<?php
include_once('common/header.php');		
$objBlog 		= new Blog();
$objBehaviour	= new Behaviour();
$intBlogId		= $objRequest->getParam('blogid', 0);
$strRefer		= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : LINK_BLOG;
$arrRow			= $objBlog->get($intBlogId);
$intError		= 0;
$arrFriend		= array();
if($AppUI->id) {
	$objBehaviour->updateRead($AppUI->id,$intBlogId,1);
}
if(isset($arrRow['status']) && abs($arrRow['status']) > 1) {
	$intError = 1; // deleted
}
if(isset($arrRow['perm'])) {
	if($arrRow['perm'] == 2 && $AppUI->id != $arrRow['userid']) { // friend
		$objVfriendUser	= new Vfriend_User();
		$arrFriend		= $objVfriendUser->getRelation($AppUI->id, 2);
		if($AppUI->id <= 0) $intError = 1;
		elseif(!$arrFriend) $intError = 1;
		elseif(isset($arrFriend) && !array_key_exists($AppUI->id, $arrFriend) && $AppUI->id > 0) $intError = 1;
	}
	elseif($arrRow['perm'] == 3) { // only me
		if($AppUI->id <=0) $intError = 1;
		elseif($AppUI->id > 0 && $AppUI->id != $arrRow['userid']) $intError = 1;
	}
}
if(isset($arrRow) && $intError == 0) {
	$arrTop				= $objBlog->getAll($AppUI->id,3,'',0,20);
	$arrRelation		= $objBlog->getAllByRelation($AppUI->id, 
													 Vfriend_Function::convertArrToStr($arrFriend),
													 $intBlogId,
													 $arrRow['title_se'],
													 0,
													 20);	
	$this->view->arrRelation	= $arrRelation;
	$this->view->row 			= $arrRow;
	$this->view->refer			= $strRefer;
	$this->view->arrTop			= $arrTop;
	include_once('blog/comment.php');	
} else {
	Vfriend_Function::setMsg($arrMessage[8]);
	if($AppUI->id > 0) {
		Vfriend_Function::redirect($strRefer);
	} else {
		Vfriend_Function::redirect(LINK_BLOG);
	}
}
?>